package com.zbkj.admin.controller.merchant;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zbkj.dal.entity.product.Parameter;
import com.zbkj.dal.base.page.CommonPage;
import com.zbkj.dal.pojo.request.PageParamRequest;
import com.zbkj.dal.pojo.request.ba.ParameterQueryRequest;
import com.zbkj.dal.pojo.response.ba.ParameterResponse;
import com.zbkj.dal.base.result.CommonResult;
import com.zbkj.service.service.ParameterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author tianzhonghai
 * 2023/11/1 08:23
 */
@Slf4j
@RestController
@RequestMapping("api/admin/merchant/parameter")
@Api(tags = "商品参数")
@Validated
public class MerchantParameterController {
    @Autowired
    private ParameterService parameterService;

    @ApiOperation(value = "分页获取参数")
    @RequestMapping(value = "/pageParameters", method = RequestMethod.POST)
    public CommonResult<CommonPage<ParameterResponse>> pageParameters(@RequestBody ParameterQueryRequest parameterQueryRequest, PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(parameterService.pageParameters(parameterQueryRequest, pageParamRequest)));
    }

    @ApiOperation(value = "获取参数")
    @RequestMapping(value = "/getParameter/{id}", method = RequestMethod.GET)
    public CommonResult<Parameter> getParameter(@PathVariable("id") Integer id) {
        return CommonResult.success(parameterService.getById(id));
    }

    @ApiOperation(value = "保存参数")
    @RequestMapping(value = "/saveParameter", method = RequestMethod.POST)
    public CommonResult<Boolean> saveParameter(@RequestBody Parameter parameter) {
        return CommonResult.success(parameterService.saveParameter(parameter));
    }

    @ApiOperation(value = "删除参数")
    @RequestMapping(value = "/deleteParameter/{id}", method = RequestMethod.DELETE)
    public CommonResult<Boolean> logicDeleteParameter(@PathVariable("id") Integer id) {
        return CommonResult.success(parameterService.logicDeleteParameter(id));
    }

    @ApiOperation(value = "获取所有参数")
    @RequestMapping(value = "/listParameters", method = RequestMethod.GET)
    public CommonResult<List<Parameter>> listParameters() {
        return CommonResult.success(parameterService.list(Wrappers.lambdaQuery(Parameter.class).eq(Parameter::getIsDel, 0)));
    }
}
